﻿@model SMECustomerWebsite.Models.ViewModels.DaoManager.ChangeDaoViewModel
@using Common.Data.Repository.Enum;
@using SMECustomerWebsite.Core.Configuration
@Html.Partial("ChangeDaoRequestDetail")
<div class="row">
    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>@SMECustomerWebsite.Core.Resources.Resource.ListChangeDaoRequest</h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                @Html.Partial("PartialRejectChangeDaoRequest")
                @if (Request.Cookies[Model.CurrentUser.UserName + "CHDError"] != null)
                {
                    <div class="alert alert-danger alert-dismissible fade in" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        @Request.Cookies[Model.CurrentUser.UserName + "CHDError"].Value
                    </div>
                }
                else if (Request.Cookies[Model.CurrentUser.UserName + "CHDSuccess"] != null)
                {
                    <div class="alert alert-success alert-dismissible fade in" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        @Request.Cookies[Model.CurrentUser.UserName + "CHDSuccess"].Value
                    </div>
                }
                @if (Model.CurrentUser.GroupIdentifier.Equals("1") && Model.CurrentUser.DepartmentId == 11)
                {
                    @Html.Partial("ImportResultChangeDaoRequest", "DaoManager")
                    <div class="col-md-6 cm-search-box">
                        @using (Html.BeginForm("ExportDataChangeDaoRequestToIT", "DaoManager", FormMethod.Post, new { @class = "sme-form-export" }))
                        {
                            <input type="submit" name="btnExportLicensing" style="width: 140px;" value="Export to excel" id="exportLicensing" class="btn btn-success right" data-toggle="tooltip" data-placement="top" title="" data-original-title="Export list of approved requests in excel to IT Division" />
                        }
                        <div class="sme-form-export">
                            <button name="btnImportLicensing" style="width: 140px;" value="Import Form" id="importResult" class="btn btn-success right" data-toggle="tooltip" data-placement="top" data-original-title="Improt result from IT Division">Import Result</button>
                        </div>
                    </div>
                }
                else if (SystemConfiguration.UserHOApprovedDao.Contains(Model.CurrentUser.UserName))
                {
                    //using (Html.BeginForm("ExportDataChangeDaoRequestDeviation", "DaoManager", FormMethod.Post, new { @class = "sme-form-export" }))
                    //{
                    @Html.Partial("PartialChooseConditionExportBMO")
                    <div class="sme-form-export">
                        <input name="btnExportLicensing" style="width: 140px;" onclick="showChooseConditionExport()" value="Export to excel" id="exportLicensingBMO" class="btn btn-success right" data-toggle="tooltip" data-placement="top" title="" data-original-title="Xuất danh sách chuyển DAO theo các tiêu chí tự chọn" />
                    </div>
                    //}
                }
                @switch (Model.CurrentUser.GroupIdentifier)
                {
                    case "1":
                        <table id="msbo-hr-manager" class="custom_table table table-bordered table-striped jambo_table bootstrap-datatable datatable">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.UserRequestHeader.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                    <th class="column-title" style="width:20% !important;">@SMECustomerWebsite.Core.Resources.Resource.ReasonHeader.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                    <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        break;
                    case "2":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.UserRequestHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ReasonHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "3":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.UserRequestHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ReasonHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "4":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.UserRequestHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ReasonHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "6":
                    <table id="msbo-hr-manager" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestId.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.UserRequestHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.ReasonHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader</th>
                                <th class="column-title" width="10%">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    default:
                        break;
                }
                @if (Model.CurrentUser.GroupIdentifier.AsInt() >= 3)
                {
                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-12 col-sm-12 col-xs-12" style=" text-align: center;">
                            @Html.ActionLink(SMECustomerWebsite.Core.Resources.Resource.AddNewBtn, "AddChangeDaoRequest", "DaoManager", new { @class = "btn btn-primary", @id = "pm-ap-cancel-btn" })
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>
<style>
    .daterangepicker {
        z-index: 1600 !important; /* has to be larger than 1050 */
    }
</style>
@section scripts
{
    <!-- Add fancyBox main JS and CSS files -->
    <script type="text/javascript" src="~/Scripts/vendors/fancyImage/jquery.fancybox.js"></script>
    <link rel="stylesheet" type="text/css" href="~/Scripts/vendors/fancyImage/jquery.fancybox.css" media="screen" />
    <script src="/scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <!-- iCheck -->
    <script src="~/Scripts/vendors/iCheck/icheck.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            eraseCookie('@Model.CurrentUser.UserName'+ 'CHDSuccess');
            eraseCookie('@Model.CurrentUser.UserName'+ 'CHDError');
            var lcColumn = [
                        { "sName": "CIF", "bSortable": true },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }]
            var lcLenCol = 5;
            var lcCifCol = 0;
            switch (@Model.CurrentUser.GroupIdentifier) {
                case 1:
                    lcColumn = [
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": true },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 7;
                    lcCifCol = 2;
                    break;
                case 2:
                    lcColumn = [
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": true },
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 6;
                    lcCifCol = 1;
                    break;
                case 3:
                    lcColumn =  [
                        { "sName": "CIF", "bSortable": true },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "DATE OPEN CIF", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 5;
                    lcCifCol = 0;
                    break;
                default:
                    break;
            }
            var tablevip = $('#msbo-hr-manager').DataTable({
                "paging": true,
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                "sAjaxSource": '@Url.Action("ListChangeDaoRequestData", "DaoManager")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns": lcColumn,
                "aoColumnDefs": [{
                    "sClass": "column-title",
                    "width": "20%",
                    "aTargets": [lcLenCol-2]
                },{
                    "sClass": "column-title",
                    "width": "12%",
                    "aTargets": [lcLenCol],
                    "mRender": function (data, type, full) {
                        var html='';
                        if (full[lcLenCol]!='') {
                            html = html + '<a class="btn btn-primary btn-xs sme_tooltip" onclick="showDetailRequest(\'' + full[lcLenCol] + '\',' + full[lcLenCol+1] + ',' + full[lcLenCol + 3] + ');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Thông tin chi tiết yêu cầu"><i class="fa fa-info"></i></a>';
                        }
                        if (full[lcLenCol + 1]) {
                            if ('@Model.CurrentUser.GroupIdentifier'=='1' &&'@Model.CurrentUser.DepartmentId'=='11') {
                                html = html + '<a class=\"btn btn-primary btn-xs sme_tooltip\" onclick="approved(\'' + full[lcLenCol] + '\');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Phê duyệt yêu cầu"><i class="fa fa-check"></i></a>';
                            } else {
                                html = html + '<a class=\"btn btn-primary btn-xs sme_tooltip\" onclick="showDetailRequest(\'' + full[lcLenCol] + '\',' + full[lcLenCol + 1] + ',' + full[lcLenCol + 3] + ');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Xác nhận và phê duyệt yêu cầu"><i class="fa fa-check"></i></a>';
                            }
                        }
                        if (full[lcLenCol+2]) {
                            html = html + '<a class=\"btn btn-danger btn-xs sme_tooltip\"  onclick="reject(\'' + full[lcLenCol] + '\');" data-toggle="tooltip" data-placement="left" title="" data-original-title="Từ chối yêu cầu"><i class="fa fa-times"></i></a>';
                        }
                        return html;
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone)');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.CreateRequestDateHeader)':
                                createFilterDate(column);
                                break;
                            case '@Html.Raw(@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(@SMECustomerWebsite.Core.Resources.Resource.ReasonHeader.ToUpper())':
                                var option = [{ id: '-1', text: 'All' }, { id: '1', text: 'Do cán bộ Vận hành gán nhầm DAO' }, { id: '2', text: 'Do phân bổ lại cán bộ quản lý khách hàng' }, { id: '3', text: 'Do CBBH nghỉ việc/buộc thôi việc/điều chuyển sang bộ phận không thực hiện công tác bán hàng' }, { id: '4', text: 'Do CBBH nghỉ thai sản' }, { id: '5', text: 'Hoàn trả lại Khách hàng cán bộ quản lý do gán nhờ mã DAO' }, { id: '6', text: 'Chuyển giao khách hàng giữa MBD/MBE và Farmer; KMBO/SBO và PMBO' }, { id: '7', text: 'Lý do khác' }]
                                createFilterCustType(column,option,1);
                                break;
                            case '@Html.Raw(@SMECustomerWebsite.Core.Resources.Resource.RequestStatusHeader)':
                                var option = [{ id: '-1', text: 'All' },{ id: '0', text: 'Creating' },{ id: '1', text: 'Requesting' }, { id: '2', text: 'Head of SME Branch/Hub Approved' }, { id: '10', text: 'Head of region Approved' }, { id: '3', text: 'HO SME Approved' }, { id: '4', text: 'IT Proccessing' }, { id: '5', text: 'Successfully' }, { id: '6', text: 'Rejected' }, { id: '14', text: 'Reject by user request' }, { id: '11', text: 'Head of SME Branch/Hub Rejected' }, { id: '12', text: 'Head of region Rejected' }, { id: '13', text: 'BIC Rejected' }, { id: '8', text: 'Send mail' }, { id: '9', text: 'Rejected and send mail' }]
                                createFilterCustType(column,option,2);
                                break;
                            default:
                                if (column.index() < lcLenCol) {
                                    var select = $('<input type="text" class="filtet-table">')
                                                            .appendTo($(column.header()))
                                                            .on('keyup change', function () {
                                                                column.search(this.value).draw();
                                                            });
                                }
                                break;
                        }
                    });
                },
                "fnDrawCallback": function (oSettings) {
                    $(".sme_tooltip").tooltip();
                }
            });

        })
        var listProduct= [];
        var tableDetailRequest;
        //show document image
        function showDetailRequest(id, isApproved,isDeviation) {
            $('#hid_request_id').val(id);

            tableDetailRequest = $('#change_dao_request_detail_tb').DataTable({
                destroy: true,
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                bFilter: false,
                bInfo: false,
                bPaginate: false,
                "sAjaxSource": '@Url.Action("ChangeDaoCifRequestDetail", "DaoManager")' + '?requestId=' + id,
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "createdRow": function ( row, data, index ) {
                    if (data[8] == true) {
                        $(row).addClass('disable');
                    }else {
                        if (data[10].IsSameSegment == false) {
                            $(row).addClass('change_dao_warning');
                        }
                        if (data[10].IsLast6MonthUpdate == true) {
                            $(row).addClass('change_dao_alert');
                        }
                    }

                    for(i=0;i<data[6].length; i++){
                        var row = [];
                        name = 'chkbox_cdproduct_'+ data[6][i].Id;
                        row.push(name);
                        if (data[6][i].NeedApprove == true) {
                            if (data[6][i].Status  == '3') {
                                row.push(false);
                            }else {
                                row.push(true);
                            }
                        }
                        listProduct.push(row);
                    };
                },
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns": [
                    { "sName": "CIF", "bSortable": false },
                    { "sName": "CIF", "bSortable": false },
                            { "sName": "USERNAME", "bSortable": false },
                            { "sName": "USERNAME", "bSortable": false },
                            { "sName": "USERNAME", "bSortable": false },
                            { "sName": "STATUS", "bSortable": false },
                            { "sName": "INFO","className": 'column-title details-control',  "bSortable": false }],
                "aoColumnDefs": [{
                    "sClass": "a-center ",
                    "aTargets": 0,
                    "mRender": function (data, type, full) {
                        if (isApproved && full[10].NeedApprove == true) {
                            if (full[7] == false) {
                                return '<input type="checkbox" class="flat" id="chkbox_ccif_' + data + '" name="chkbox_ccif_' + data + '">';
                            } else {
                                return '<input type="checkbox" class="flat" id="chkbox_ccif_' + data + '" name="chkbox_ccif_' + data + '" checked>';
                            }
                        } else {
                            if (full[9] == '2'||full[9] == '1') {
                                return '<i class="fa fa-check"></i>';
                            }else {
                                return '';
                            }
                        }
                    }
                },{
                    "sClass": "column-title",
                    "aTargets": [6],
                    "mRender": function (data, type, full) {
                        if (data.length == 0) {
                            return 'Customer don\' t have any product in your branch';
                        }else {
                            return '<a class=\"btn btn-primary btn-xs show_detail_row\" \"><i class="fa fa-plus-square"></i></a>';
                        }
                    }
                }],
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });
            if (isDeviation) {
                if (isApproved && ('@Model.CurrentUser.GroupIdentifier'=='1' || '@Model.CurrentUser.GroupIdentifier'=='2' ||'@Model.CurrentUser.GroupIdentifier'=='3' )) {
                    $('#isDeviationLbl').hide();
                    $('#div_check_deviation').show()
                    $('#chkbox_is_deviation').prop("checked", true);
                }else {
                    $('#chkbox_is_deviation').prop("checked", false);
                    $('#isDeviationLbl').show();
                    $('#div_check_deviation').hide()
                    $('#isDeviationLbl').text("Yêu cầu tính kết quả cho tháng trước")
                }
            }else{
                $('#div_check_deviation').hide()
                $('#isDeviationLbl').hide();
            }
            if (isApproved) {
                $('#submit_changedao_btn_modal').show();
            } else {
                $('#submit_changedao_btn_modal').hide();
            }
            $('#change_dao_request_detail_modal').modal('show');
        };


        function change(dis){
            for (i=0; i< listProduct.length; i++){
                if (listProduct[i][0]== dis.name) {
                    listProduct[i][1]=dis.checked;
                }
            }
        }
        $('#change_dao_request_detail_tb').on('click', 'td.details-control .show_detail_row', function () {
            var tr = $(this).closest('tr');
            var row = tableDetailRequest.row(tr);

            if (row.child.isShown()) {
                // This row is already open - close it
                row.child(format(row.data())).hide();
                tr.removeClass('shown');
                $('tr td a.show_detail_row i').addClass('fa-plus-square');
                $('tr td a.show_detail_row i').removeClass('fa-minus-square');
            }
            else {
                // Open this row
                var dataRow = row.data();
                var detail = row.child(format(row.data())).show();
                tr.addClass('shown');
                $('tr.shown td a.show_detail_row i').removeClass('fa-plus-square');
                $('tr.shown td a.show_detail_row i').addClass('fa-minus-square');
            }
        });


        function format(d) {
            var position=6;
            // `d` is the original data object for the row
            var html = '<table class="table table-child table_overdue custom_table table-bordered table-striped jambo_table"  cellpadding="5" cellspacing="0" border="0"><th class="column-title">Check</th><th class="column-title">TYPE</th><th class="column-title">NO.</th><th class="column-title">Old DAO</th><th class="column-title">DATA DATE</th>';
            if (d[position].length==0) {
                html = html+
                    '<tr>'+
                    '<td colspan="'+position+'">NO DATA</td>'+
                    '</tr>';
            }
            var isCheck;
            var classDisable;
            var idProduct;
            for (var i = 0; i < d[position].length; i++) {
                idProduct = d[position][i].Id;
                if (d[position][i].NeedApprove == true) {
                    if (d[position][i].Status  == '3') {
                        isCheck = '<input type="checkbox" class="flat chkbox_cdproduct" onchange="change(this)" id="chkbox_cdproduct_' + idProduct + '" name="chkbox_cdproduct_' + idProduct + '" >';
                    }else {
                        isCheck = '<input type="checkbox" class="flat chkbox_cdproduct" onchange="change(this)" id="chkbox_cdproduct_' + idProduct + '" name="chkbox_cdproduct_' + idProduct + '" checked>';
                    }
                } else {
                    if (d[position][i].Status  == '2'||d[position][i].Status  == '1') {
                        isCheck= '<i class="fa fa-check"></i>';
                    }else {
                        isCheck= '';
                    }
                }
                if (d[position][i].Status == '@Common.Data.Repository.Enum.StatusChangeDaoCifEnum.Reject') {
                    classDisable = '<tr class="disable">'
                } else {
                    classDisable = '<tr>'
                }
                html = html+
                    classDisable +
                    '<td>' + isCheck + '</td>' +
                    '<td>'+d[position][i].TypeProduct+'</td>'+
                     '<td>'+d[position][i].NoProduct+'</td>'+
                     '<td>'+d[position][i].Dao+'</td>'+
                     '<td>'+d[position][i].DataDate+'</td>'+
                     '</tr>';
            }
            html = html + '</table>';
            return html;
        }
        $('#exportLicensing').click(function () {
            location.reload();
        });

        $('#importForm').click(function () {
            $('#import_form_modal').modal('show');
        });
        $('#importResult').click(function () {
            $('#import_result_modal').modal('show');
        });
        //approve request
        function approved(id) {
            $.ajax({
                url: '@Url.Action("ApproveChangeDaoRequest", "DaoManager")',
                type: "POST",
                data: { request: id},
                success: function (data_response) {
                    if (data_response.IsSuccess == true) {
                        createCookie('@Model.CurrentUser.UserName'+ 'CHDSuccess', 'Approved request successfull', 1)
                    } else {
                        createCookie('@Model.CurrentUser.UserName'+ 'CHDError', 'Approved request fail', 1)
                    }
                    location.reload();
                }
            })
        };

        function submitData() {
            if (confirm('Are you sure?')) {
                var data = $('[name^=chkbox_ccif_]');
                var content = [];
                data.each(function (index, item) {
                    var row = [];
                    row.push(item.name);
                    row.push(item.checked);
                    content.push(row);
                });
                var jsonData = JSON.stringify(content);
                var jsonDataProduct = JSON.stringify(listProduct);
                var isDeviation =$('#chkbox_is_deviation')[0].checked;
                $.ajax({
                    url: '@Url.Action("UpdateChangeDaoCif", "DaoManager")',
                    type: "POST",
                    data: { dataCif: jsonData, dataProduct: jsonDataProduct, requestId: $('#hid_request_id').val(), check: isDeviation  },
                    success: function (data_response) {
                        if (data_response != '') {
                            if (data_response.MessageType == 0) {
                                createCookie('@Model.CurrentUser.UserName'+ 'CHDSuccess', data_response.Message, 1)
                            } else {
                                createCookie('@Model.CurrentUser.UserName'+ 'CHDError', data_response.Message, 1)
                            }
                            location.reload();
                        }
                    }
                })
            } else {
            }
            return false;
        }

        function showChooseConditionExport() {
            var option = [{ id: '-1', text: 'All' },{ id: '0', text: 'Creating' },{ id: '1', text: 'Requesting' }, { id: '2', text: 'Head of SME Branch/Hub Approved' }, { id: '10', text: 'Head of region Approved' }, { id: '3', text: 'HO SME Approved' }, { id: '4', text: 'IT Proccessing' }, { id: '5', text: 'Successfully' }, { id: '6', text: 'Rejected' }, { id: '14', text: 'Reject by user request' }, { id: '11', text: 'Head of SME Branch/Hub Rejected' }, { id: '12', text: 'Head of region Rejected' }, { id: '13', text: 'BIC Rejected' }, { id: '8', text: 'Send mail' }, { id: '9', text: 'Rejected and send mail' }]
            $('#choose_Status').select2({
                placeholder: "Select status",
                data: option
            });


            var cb = function (start, end, label) {
                $('#create_date_range span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
            };

            var optionSet1 = {
                startDate: moment(),
                endDate: moment(),
                showDropdowns: true,
                showWeekNumbers: true,
                timePicker: false,
                timePickerIncrement: 1,
                timePicker12Hour: true,
                opens: 'left',
                buttonClasses: ['btn btn-default'],
                applyClass: 'btn-small btn-primary sme-pick-range-date',
                cancelClass: 'btn-small',
                format: 'DD/MM/YYYY',
                separator: ' - ',
                locale: {
                    applyLabel: 'OK',
                    cancelLabel: 'Clear',
                    fromLabel: 'From',
                    toLabel: 'To',
                    customRangeLabel: 'Custom',
                    daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
                    monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                    firstDay: 1
                }
            };


            $('#create_date_range span').html(moment().subtract(29, 'days').format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));

            $('#create_date_range').daterangepicker(optionSet1, cb);

            $('#choose_condition_modal').modal('show');
            return false;
        }
    </script>
    @if (Model.CurrentUser.GroupIdentifier.Equals("4") || Model.CurrentUser.GroupIdentifier.Equals("6"))
    {
        <script type="text/javascript">
            //reject request
            function reject(id) {

                $.ajax({
                    url: '@Url.Action("RejectChangeDaoRequest", "DaoManager")',
                    type: "POST",
                    data: { request: id},
                    success: function (data_response) {
                        if (data_response.IsSuccess == true) {
                            createCookie('@Model.CurrentUser.UserName'+ 'CHDSuccess', 'Reject request successfull', 1)
                        } else {
                            createCookie('@Model.CurrentUser.UserName'+ 'CHDError', 'Reject request fail', 1)
                        }
                        location.reload();
                    }
                })
            };
        </script>
    }
    else
    {
        <script type="text/javascript">
            //reject request
            function reject(id) {
                $('#Request_Id_Reject').val(id);
                $('#reject_change_dao_modal').modal('show');
            };
        </script>
    }
}